﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using MINERP.COM;
using MINERP.ComControls;
using MINERP.DisjoinProForOutShop.Forms;
using MINERP.DisjoinProForOutShop.IView;
using MINERP.DisjoinProForOutShop.Presenter;
using MINERP.MODEL.DisjoinProForOutShop;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.OverOrder;
using MINERP.NewProject;

namespace MINERP.DisjoinProForOutShop
{
    public partial class FrmMain : FrmParent, IView.IFrmMain
    {
        public FrmMain()
        {
            InitializeComponent();
            base.InitiAuthority();
            _presenter = new MainPresenter(this);

        }

//        public Hashtable hashGrid = new Hashtable();//委外

        MainPresenter _presenter;
        public Hashtable hashGrid { get; set; }

        public bool GetIsForcePrint
        {
            get { return IsForcePrint.Checked; }
        }

        public bool IsPrintFahuo
        {
            get;
            set;
        }

        public int OperateUserId
        {
            get
            {
                this.lblCurrentUser.Text = base.userName;
                return base.userId;

            }
            set { }
        }
        public List<OverOrderView> ShopInGrid { get; set; }
        public string ProductBarCode
        {
            get;
            set;
        }

        public GridSubArea_Info CurrShopSubares
        {
            get;
            set;
        }

        public GridSubArea_Info CurrOutShopSubares
        {
            get;
            set;
        }

        public bool IsMouseClickGrid = true;
        
        public void NewChangeGridColor(Grid_Info Grid)
        {

            Color saveColor = ((UGrid)hashGrid[Grid.GridId]).BackColor;
            if (OldGridColor.Count < 1)
            {
                OldGridColor.Add(Grid.GridId, saveColor);

            }
            else
            {

                int oldGridId = Convert.ToInt32(OldGridColor.Keys.FirstOrDefault());
                Color oldColor = OldGridColor[oldGridId];
                if (Grid.GridId == oldGridId)
                {
                    return;
                }
                if (CheckTimeOutH(oldGridId))
                {
                    if (oldColor == Color.Blue)
                    {
                        ((UGrid)hashGrid[oldGridId]).BackColor = Color.Blue;
                    }
                    else if (oldColor == Color.LightBlue)
                    {
                        if ((UGrid)hashGrid[oldGridId] != null)
                        {
                            ((UGrid)hashGrid[oldGridId]).BackColor = Color.LightBlue;
                        }
                    }
                    else
                    {
                        if ((UGrid)hashGrid[oldGridId] != null)
                        {
                            ((UGrid)hashGrid[oldGridId]).BackColor = Color.Orange;
                        }
                    }
                }
                else
                {
                    //if (((UGrid)hashGrid[oldGridId]).f)
                    if (CheckTimeOutNULL(oldGridId))
                    {
                        if ((UGrid)hashGrid[oldGridId] != null)
                        {
                            ((UGrid)hashGrid[oldGridId]).BackColor = Color.White;
                        }
                    }
                    else
                    {
                        if ((UGrid)hashGrid[oldGridId] != null)
                        {
                            ((UGrid)hashGrid[oldGridId]).BackColor = oldColor;
                        }
                    }
                    
                }

                OldGridColor = new Dictionary<int, Color>();

                OldGridColor.Add(Grid.GridId, saveColor);

            }
            ((UGrid)hashGrid[Grid.GridId]).BackColor = Color.LightPink;
            //if(Grid.GridType==(int)GridType.Custom)
            //{
            //    if(CurrentGrid.CurrentCount==
            //}
           

        }
        private Grid_Info _currentGrid;
        public Grid_Info CurrentGrid
        {
            set
            {
                //if (this._currentGrid != null)
                //{
                //    //ChangeGridColor(this._currentGrid.GridId, Color.White);

                //    //CheckTimeOutH(this._currentGrid);
                //    this._currentGrid = value;
                //    //CheckTimeOut(this._currentGrid);

                //}
                //else
                //{
                //    _currentGrid = value;
                //    ChangeGridColor(_currentGrid.GridId, Color.LightPink);

                //}


                _currentGrid = value;
                NewChangeGridColor(_currentGrid);
                // string aaa = ((UGrid)hashGrid[_currentGrid.GridId]).GetType().Name;


            }
            get
            {
                return _currentGrid;
            }
        }

        public void CheckTimeOut(Grid_Info grid)
        {
            if (grid != null)
            {
                if (grid.GetType().Name.ToString().Equals("OutShopGrid_Info"))
                {
                    //if (grid.SomeId != 0 && (DateTime.Now - grid.FirstEnterTime).TotalMinutes.CompareTo(this.CurrOutShopSubares.OutTimeAlarmTime) > 0)
                    //{
                    //    if (grid.SomeId != 0 && (DateTime.Now - grid.FirstEnterTime).TotalMinutes.CompareTo(this.CurrOutShopSubares.OutTimeAlarmTime) > 0)
                    //{

                    //    ChangeGridColor(grid.GridId, Color.Red);
                    //}
                    //else
                    //{

                    ChangeGridColor(grid.GridId, Color.LightPink);
                    //}
                }
                else if (_currentGrid.GetType().Name.ToString().Equals("ShopGrid_Info"))
                {
                    //if (_currentGrid.SomeId != 0 && (DateTime.Now - this._currentGrid.FirstEnterTime).TotalMinutes.CompareTo(this.CurrShopSubares.OutTimeAlarmTime) > 0)
                    //{

                    //    ChangeGridColor(grid.GridId, Color.Red);
                    //}
                    //else
                    //{

                    //    ChangeGridColor(grid.GridId, Color.LightPink);
                    //}
                    ChangeGridColor(grid.GridId, Color.LightPink);
                }
            }
        }
        public bool CheckTimeOutH(Grid_Info grid)
        {
            if (grid.GetType().Name.ToString().Equals("OutShopGrid_Info"))
            {
                if (grid.SomeId != 0 && (DateTime.Now - grid.FirstEnterTime).TotalMinutes.CompareTo(this.CurrOutShopSubares.OutTimeAlarmTime) > 0)
                {

                    //ChangeGridColor(grid.GridId, Color.Red);
                    return true;
                }

            }
            else if (grid.GetType().Name.ToString().Equals("ShopGrid_Info"))
            {
                if (grid.SomeId != 0 && (DateTime.Now - this._currentGrid.FirstEnterTime).TotalMinutes.CompareTo(this.CurrShopSubares.OutTimeAlarmTime) > 0)
                {

                    //ChangeGridColor(grid.GridId, Color.Red);
                    return true;
                }

            }
            return false;
        }
        public bool CheckTimeOutH(int gridid)
        {

            UGrid UGrid = (UGrid)hashGrid[gridid];
            if (UGrid != null)
            {
                if (UGrid.GetType().Name.ToString().Equals("OutShopUGrid"))
                {
                    OutShopUGrid outshop = ((OutShopUGrid)((UGrid)hashGrid[gridid]));

                    if (outshop.OutShopId != 0 && (DateTime.Now - outshop.FristEnterTime).TotalMinutes.CompareTo(this.CurrOutShopSubares.OutTimeAlarmTime) > 0)
                    {

                        return true;
                    }

                }
                else if ((UGrid).GetType().Name.ToString().Equals("ShopUGrid"))
                {
                    ShopUGrid outshop = ((ShopUGrid)((UGrid)hashGrid[gridid]));
                    //if (outshop.FristEnterTime.ToString().StartsWith("2000"))
                    //    return false;
                    if (outshop.ShopId != 0 && (DateTime.Now - outshop.FristEnterTime).TotalMinutes.CompareTo(this.CurrShopSubares.OutTimeAlarmTime) > 0)
                    {

                        //ChangeGridColor(grid.GridId, Color.Red);
                        return true;
                    }

                }
            }
            return false;
        }
        public bool CheckTimeOutNULL(int gridid)
        {
            //DateTime time = ((ShopUGrid)((UGrid)hashGrid[_currentGrid.GridId])).FristEnterTime;
            UGrid UGrid = (UGrid)hashGrid[gridid];
            if (UGrid != null)
            {
                //UGrid.
                //((UGrid)hashGrid[gridid]).GetType().Name
                if (UGrid.GetType().Name.ToString().Equals("OutShopUGrid"))
                {
                    OutShopUGrid outshop = ((OutShopUGrid)((UGrid)hashGrid[gridid]));
                    if (outshop.OutShopId == 0)
                        return true;


                }
                else if ((UGrid).GetType().Name.ToString().Equals("ShopUGrid"))
                {
                    ShopUGrid outshop = ((ShopUGrid)((UGrid)hashGrid[gridid]));
                    if (outshop.ShopId == 0)
                        return true;


                }
            }
            return false;
        }

        public void InitialOutShopGrid(List<OutShopGrid_Info> listOutGrid, GridSubArea_Info subArea)
        {
           

            tableLayoutPanelOutOrder.Controls.Clear();

            tableLayoutPanelOutOrder.RowStyles.Clear();
            tableLayoutPanelOutOrder.ColumnStyles.Clear();
            tableLayoutPanelOutOrder.RowCount = subArea.WidthNum;
            tableLayoutPanelOutOrder.ColumnCount = subArea.HeightNum;
            int panelWigth = 0;
            if (splitContainer_Grid.Panel2Collapsed == true)
            {
                panelWigth = splitContainer_Grid.Width;

            }
            else
            {
                panelWigth = splitContainer_Grid.Panel1.Width;
            }

            int panelHeight = splitContainer_Grid.Panel1.Height;

            int gWidth = (panelWigth - (subArea.WidthNum - 1) * 7) / subArea.WidthNum - 1;//格子的宽
            int gheight = (panelHeight - (subArea.HeightNum - 1) * 7) / subArea.HeightNum - 1;//格子的高


            foreach (OutShopGrid_Info grid in listOutGrid)
            {


                OutShopUGrid outShopUGrid = new OutShopUGrid();

                outShopUGrid.Width = gWidth;
                outShopUGrid.Height = gheight;
                outShopUGrid.GridId = grid.GridId;
                outShopUGrid.GridName = grid.GridName;
                outShopUGrid.Grid = grid;
                outShopUGrid.FristEnterTime = grid.FirstEnterTime;
                outShopUGrid.CompleteTime = grid.CompleteTime;
                outShopUGrid.OutShopClick += new OutShopUGrid.PostClicks(outShopUGrid_Click);
                outShopUGrid.OutShopDoubleClick += new OutShopUGrid.PostClicks(outShopUGrid_DoubleClick);
                if (grid.OutShop != null && grid.OutShop.OutShopId != 0)
                {
                    outShopUGrid.OutShopId = grid.OutShop.OutShopId;
                    outShopUGrid.OutShopName = grid.OutShop.OutShopName;
                    outShopUGrid.AllNum = grid.TotalCount;
                    outShopUGrid.CurrNum = grid.CurrentCount;
                    outShopUGrid.FristEnterTime = grid.FirstEnterTime;
                    if ((DateTime.Now - outShopUGrid.FristEnterTime).TotalMinutes >= this.CurrOutShopSubares.OutTimeAlarmTime)
                    {
                        outShopUGrid.BackColor = Color.Red;
                    }
                    else
                    {
                        outShopUGrid.BackColor = Color.GreenYellow;
                    }
                }
                else
                {
                    if ((DateTime.Now - outShopUGrid.CompleteTime).TotalMinutes >= this.CurrOutShopSubares.GridClearTime)
                    {
                        outShopUGrid.OutShopName = "";
                        outShopUGrid.CurrNum = 0;
                        outShopUGrid.AllNum = 0;

                    }

                }
                if (!hashGrid.ContainsKey(outShopUGrid.GridId))
                {
                    hashGrid.Add(outShopUGrid.GridId, outShopUGrid);
                }
                tableLayoutPanelOutOrder.Controls.Add(outShopUGrid);

            }
        }
        void outShopUGrid_DoubleClick(OutShopUGrid uGrid)
        {
            IsMouseClickGrid = true;
            this.CurrentGrid = uGrid.Grid;
            if (uGrid.Grid != null && uGrid.Grid.SomeId != 0)
            {

                _presenter.ShowGridDetail();
                OutShopGrid_Info outShopInfo = (OutShopGrid_Info)(uGrid.Grid);
                if (outShopInfo.OutShop != null)
                {
                    textEditCode.Text = outShopInfo.OutShop.Code;
                    textEditShopName.Text = outShopInfo.OutShop.OutShopName;
                    textEdit_Keeper.Text = outShopInfo.OutShop.Keeper;
                    textEditCity.Text = outShopInfo.OutShop.City;
                }
            }
            else
            {
                textEditCode.Text = "";
                textEditShopName.Text = "";
                textEdit_Keeper.Text = "";
                textEditCity.Text = "";
                gridControl_product.DataSource = null;
            }

            splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Both;
            splitContainerControl_right.Panel1Collapsed = false;
            splitContainerControl_right.Panel2Collapsed = true;
            if (CurrentGrid.SomeId == 0)
            {
                toolStripButtonClearGrid.Enabled = false;
                tsbtnPrint.Enabled = false;
            }
            else
            {
                toolStripButtonClearGrid.Enabled = true;
                tsbtnPrint.Enabled = true;
            }
        }

        private void outShopUGrid_Click(OutShopUGrid uGrid)
        {
            //this.CurrentGrid = uGrid.Grid;
            this.IsMouseClickGrid = true;
            this.CurrentGrid = uGrid.Grid;
            if (splitContainerControl_Botoom.PanelVisibility == SplitPanelVisibility.Both)
            {
                if (uGrid.Grid != null && !string.IsNullOrEmpty(uGrid.OutShopName))
                {

                    _presenter.ShowGridDetail();
                    OutShopGrid_Info outShopInfo = (OutShopGrid_Info)(uGrid.Grid);
                    if (outShopInfo.OutShop != null)
                    {
                        textEditCode.Text = outShopInfo.OutShop.Code;
                        textEditShopName.Text = outShopInfo.OutShop.OutShopName;
                        textEdit_Keeper.Text = outShopInfo.OutShop.Keeper;
                        textEditCity.Text = outShopInfo.OutShop.City;
                    }
                }
                else
                {
                    textEditCode.Text = "";
                    textEditShopName.Text = "";
                    textEdit_Keeper.Text = "";
                    textEditCity.Text = "";
                    gridControl_product.DataSource = null;
                }

                splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Both;
                splitContainerControl_right.Panel1Collapsed = false;
                splitContainerControl_right.Panel2Collapsed = true;
            }
            if (CurrentGrid.SomeId == 0)
            {
                toolStripButtonClearGrid.Enabled = false;
                tsbtnPrint.Enabled = false;
            }
            else
            {
                toolStripButtonClearGrid.Enabled = true;
                tsbtnPrint.Enabled = true;
            }
        }

        public void InitailShopGrid(List<ShopGrid_Info> listShopGrid, GridSubArea_Info subArea)
        {
           
            splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Panel1;//先收缩右边的详细列表
            hashGrid.Clear();
            tableLayoutPanelEndOrder.Controls.Clear();
            tableLayoutPanelEndOrder.RowStyles.Clear();
            tableLayoutPanelEndOrder.ColumnStyles.Clear();
            tableLayoutPanelEndOrder.RowCount = subArea.WidthNum;
            tableLayoutPanelEndOrder.ColumnCount = subArea.HeightNum;
            tableLayoutPanelEndOrder.Padding = new System.Windows.Forms.Padding(1, 0, 1, 0);
            int panelWigth = 0;

            if (splitContainer_Grid.Panel1Collapsed == true)
            {
                panelWigth = splitContainer_Grid.Width;
            }
            else
            {
                panelWigth = splitContainer_Grid.Panel2.Width;
            }

            int panelHigth = splitContainer_Grid.Panel2.Height;
            //int GZwidth = (panelWigth - (subArea.WidthNum - 1) * 7) / subArea.HeightNum;//格子的宽
            //int ZGheight = (panelHigth - (subArea.HeightNum - 1) * 7) / subArea.WidthNum;//格子的高
            int GZwidth = 250;
            int ZGheight = 100;
            foreach (ShopGrid_Info grid in listShopGrid)
            {

                ShopUGrid uGrid = new ShopUGrid();
                uGrid.Width = GZwidth;
                uGrid.Height = ZGheight;
                uGrid.GridId = grid.GridId;
                uGrid.GridName = grid.GridName;
                uGrid.FristEnterTime = grid.FirstEnterTime;
                uGrid.OrderTime = grid.OrderEnterTime.ToString("yy-MM-dd HH:mm");
                uGrid.OrderName = grid.OrderName;
                uGrid.CtmName = grid.CtmName;
                uGrid.OrderNum = grid.DisplayNum;
                uGrid.CompleteTime = grid.CompleteTime;
                uGrid.Grid = grid;
                uGrid.Padding = new System.Windows.Forms.Padding(1, 0, 1, 0);
                uGrid.ShopClick += new ShopUGrid.PostClicks(UGridClick);
                uGrid.ShopDoubleClick += new ShopUGrid.PostClicks(GridDoubleClick);
                if (grid.Shop != null)
                {
                    uGrid.ShopId = grid.SomeId;
                    uGrid.ShopName = grid.Shop.ShopName;
                    //uGrid.NumCurr = grid.CurrentCount;
                    if ((DateTime.Now - uGrid.FristEnterTime).TotalMinutes.CompareTo(this.CurrShopSubares.OutTimeAlarmTime) > 0)
                    {
                        uGrid.BackColor = Color.Orange;
                    }
                    else
                    {
                        uGrid.BackColor = Color.GreenYellow;
                    }
                    if(grid.IsComplete)
                    {
                        uGrid.BackColor = Color.LightBlue;
                    }
                }
                else
                {
                    if ((DateTime.Now - uGrid.FristEnterTime).TotalMinutes.CompareTo(this.CurrShopSubares.GridClearTime) > 0)
                    {
                        uGrid.ShopName = "";
                        //uGrid.NumCurr =0;
                    }
                }

                if (!hashGrid.ContainsKey(uGrid.GridId))
                {
                    hashGrid.Add(uGrid.GridId, uGrid);
                }
                tableLayoutPanelEndOrder.Controls.Add(uGrid);
            }
        }

        public void GridDoubleClick(ShopUGrid uGrid)
        {
            try
            {
                this.IsMouseClickGrid = true;
                this.Cursor = Cursors.WaitCursor;
                CurrentGrid = (Grid_Info)uGrid.Grid;
               // uGrid.Grid
                //_presenter.ShowGridShopHead();
                ///显示头部信息
                Shop_Info shopInfo = ((ShopGrid_Info)uGrid.Grid).Shop;
                if (shopInfo != null && !string.IsNullOrEmpty(uGrid.ShopName))
                {

                    textEdit_ShopId.Text = shopInfo.ShopId.ToString();
                    textEdit_ShopName.Text = shopInfo.ShopName;
                    textEdit_kepper.Text = shopInfo.ShopKeeper;
                    textEdit_shopCity.Text = shopInfo.Tel1;
                }
                else
                {
                    textEdit_ShopId.Text = "";
                    textEdit_ShopName.Text = "";
                    textEdit_kepper.Text = "";
                    textEdit_shopCity.Text = "";
                }

                if (uGrid.Grid != null)
                {
                    _presenter.ShowGridDetail();
                }
                splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Both;
                splitContainerControl_right.Panel1Collapsed = true;
                splitContainerControl_right.Panel2Collapsed = false;
                if (CurrentGrid.SomeId == 0)
                {
                    toolStripButtonClearGrid.Enabled = false;
                    tsbtnPrint.Enabled = false;
                }
                else
                {
                    toolStripButtonClearGrid.Enabled = true;
                    tsbtnPrint.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

        }


        public void UGridClick(ShopUGrid uGrid)
        {
            try
            {
                IsMouseClickGrid = true;
                this.Cursor = Cursors.WaitCursor;
                if (splitContainerControl_Botoom.PanelVisibility == SplitPanelVisibility.Both)
                {

                    CurrentGrid = (Grid_Info)uGrid.Grid;

                    //_presenter.ShowGridShopHead();
                    ///显示头部信息

                    Shop_Info shopInfo = ((ShopGrid_Info)uGrid.Grid).Shop;
                    if (shopInfo != null && !string.IsNullOrEmpty(uGrid.ShopName))
                    {

                        textEdit_ShopId.Text = shopInfo.ShopId.ToString();
                        textEdit_ShopName.Text = shopInfo.ShopName;
                        textEdit_kepper.Text = shopInfo.ShopKeeper;
                        textEdit_shopCity.Text = shopInfo.Tel1;
                    }
                    else
                    {
                        textEdit_ShopId.Text = "";
                        textEdit_ShopName.Text = "";
                        textEdit_kepper.Text = "";
                        textEdit_shopCity.Text = "";
                    }

                    if (uGrid.Grid != null)
                    {
                        _presenter.ShowGridDetail();
                    }
                }
                CurrentGrid = (Grid_Info)uGrid.Grid;
                if (CurrentGrid.SomeId == 0)
                {
                    toolStripButtonClearGrid.Enabled = false;
                    tsbtnPrint.Enabled = false;
                }
                else
                {
                    toolStripButtonClearGrid.Enabled = true;
                    tsbtnPrint.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        List<OverOrderView> CurrListForRecheck = new List<OverOrderView>();
        public void ShowOutShopGridDetail(List<OverOrderView> listOrderInfo)
        {
            gridControl_product.DataSource = listOrderInfo;
            CurrListForRecheck = listOrderInfo;
        }

        void grid_DoubleClick(object sender, EventArgs e)
        {
            ChangeGridColor(this._currentGrid.GridId, Color.White);
            UGrid grid = (UGrid)sender;
            //显示商户和产品
            splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Both;
            // _presenter.ShowGridShopHead();

        }

        void grid_Click(object sender, EventArgs e)
        {
            ChangeGridColor(this._currentGrid.GridId, Color.White);
            UGrid grid = (UGrid)sender;
            //this.CurrentGrid =  
        }

        public void ShowShopInfo(OutProcessShop_Info shopInfo)
        {
            this.textEditCode.Text = shopInfo.Code;
            this.textEditCity.Text = shopInfo.City;
            this.textEditShopName.Text = shopInfo.OutShopName;
        }

        public void ClearGrid(int gridId)
        {
            _presenter.ClearCurrGrid();
        }
        public Dictionary<int, Color> OldGridColor { get; set; }
        public void ChangeGridColor(int gridId, Color newColor)
        {
            try
            {
                if (((UGrid)hashGrid[this._currentGrid.GridId]).BackColor == Color.Blue)
                {
                    return;
                }
                ((UGrid)hashGrid[this._currentGrid.GridId]).BackColor = newColor;

            }
            catch (Exception ex)
            {


            }


        }
        //public void RecoverGridColor(int gridId, Color newColor)
        //{

        //    Color saveColor = ((UGrid)hashGrid[gridId]).BackColor;
        //    if (OldGridColor.Count < 1)
        //    {
        //        OldGridColor.Add(gridId, saveColor);

        //    }
        //    else
        //    {
        //        int oldGridId = Convert.ToInt32(OldGridColor.Keys.FirstOrDefault());
        //        Color oldColor = OldGridColor[oldGridId];

        //        ((UGrid)hashGrid[oldGridId]).BackColor = oldColor;

        //        OldGridColor = new Dictionary<int, Color>();

        //        OldGridColor.Add(gridId, saveColor);

        //    }




        //}
        /// <summary>
        /// 清空当前格子
        /// </summary>
        //public void ClearGrid()
        //{

        //}

        public void Exit()
        {
            MINERP.COM.Logoff.ShowMainFrm();
        }

        public void ShowMsg(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public void SelectSubArea(List<PhotoSubarea_Info> subAreaList)
        {

            FrmSelectSubarea selectSubarea = new FrmSelectSubarea();
            if (DialogResult.OK == selectSubarea.ShowDialog())
            {

            }
            else
            {
                Exit();
            }
        }

        private void toolStripTextBox_ProductBarCode_KeyPress(object sender, KeyPressEventArgs e)
        {

            if ((int)e.KeyChar <= 31)//功能按键
            {
                return;
            }
            if (!Char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
            if (toolStripTextBox_ProductBarCode.Text.Length >= 10)
            {
                e.Handled = true;
            }
        }

        private void toolStripTextBox_ProductBarCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string strPhBarcode = toolStripTextBox_ProductBarCode.Text.Trim();
                if (strPhBarcode.Trim().Length == 0)
                {
                    return;
                }
                if (strPhBarcode.Length != 10)
                {
                    strPhBarcode = "2" + string.Format("{0:d9}", Convert.ToInt32(strPhBarcode));
                }
                _presenter.AssinGrid(strPhBarcode);
                this.toolStripTextBox_ProductBarCode.Text = "";
                strformBarcode = "";

                //if (strPhBarcode.Length != 10)
                //{
                //    MessageBox.Show("您输入的条码有误，请重新输入" + toolStripTextBox_ProductBarCode.Text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
                //else
                //{
                //    _presenter.AssinGrid(toolStripTextBox_ProductBarCode.Text.Trim());
                //    this.toolStripTextBox_ProductBarCode.Text = "";
                //    strformBarcode = "";
                //}

            }
        }

        private string strformBarcode = "";
        private StringBuilder strBuildBacode = new StringBuilder();
        private void FrmMain_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar))
            {
                strformBarcode = toolStripTextBox_ProductBarCode.Text.Trim();
                if (strformBarcode.Length >= 10)
                {
                    e.Handled = true;
                }
                else
                {
                    strBuildBacode.Append(e.KeyChar);
                }

                toolStripTextBox_ProductBarCode.Text = strBuildBacode.ToString();
            }
            else if (e.KeyChar == (char)27)//如果按的是ESC键
            {
                if (this.splitContainerControl_Botoom.PanelVisibility != SplitPanelVisibility.Panel1)
                {
                    this.splitContainerControl_Botoom.PanelVisibility = SplitPanelVisibility.Panel1;
                    //_presenter.ShowAllGrid();
                    this.CurrentGrid = CurrentGrid;
                    this.IsMouseClickGrid = false;
                    needOpen = false;
                }
            }

            else if (e.KeyChar == (char)13)//用户输入回车键
            {
                string strBarCode = toolStripTextBox_ProductBarCode.Text.Trim();

                if (strBarCode.Length != 10)
                {
                    strBarCode = "2" + string.Format("{0:d9}", Convert.ToInt32(strBarCode));
                }
                this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                _presenter.AssinGrid(strBarCode);
                strBuildBacode = new StringBuilder();
                toolStripTextBox_ProductBarCode.Text = "";
                this.Cursor = System.Windows.Forms.Cursors.Default;


                //if (strBarCode.Length != 10)
                //{
                //    MessageBox.Show("照片条码长度不为10位，请重新输入！" + strBarCode.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    strBuildBacode = new StringBuilder();
                //}
                //else
                //{
                //    this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                //    _presenter.AssinGrid(toolStripTextBox_ProductBarCode.Text.Trim());
                //    strBuildBacode = new StringBuilder();
                //    toolStripTextBox_ProductBarCode.Text = "";
                //    this.Cursor = System.Windows.Forms.Cursors.Default;
                //}
            }
            else if (e.KeyChar == (char)8)
            {
                int legth = strBuildBacode.Length;
                if (legth > 0)
                {
                    strBuildBacode = strBuildBacode.Remove(legth - 1, 1);
                    toolStripTextBox_ProductBarCode.Text = strBuildBacode.ToString();
                }
            }
            else if ((int)e.KeyChar <= 31)
            {
                return;

            }

        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //this.TechId = 10;///调试用
            //OperateUserId = 3;///调试用
            //this.lblCurrentUser.Text = "当前操作员：" + base.userName;
            this.lblCurrentUser.Text = base.userName;
            ShowType = 0;
            //_presenter.BindSubArea();
            _presenter.InitialGrids();
            OldGridColor = new Dictionary<int, Color>();
            IsMouseClickGrid = false;
            //Properties.Settings.Default
            toolStripComboBoxPrintType.SelectedIndex = Properties.Settings.Default.PrintType;
        }


        #region IFrmMain 成员

        public bool DetailIsExplan
        {
            get;
            set;
        }

        public int TechId
        {

            get { return base.CurrentTechID; }
            set { }
        }

        public int ShowType
        {
            get { return Convert.ToInt32(Properties.Settings.Default.DisplayType); }
            set
            {
                Properties.Settings.Default.DisplayType = value;
                Properties.Settings.Default.Save();
            }

        }



        public void ShowShopGridDetail(List<OverOrderView> listDetail)
        {
            ShopInGrid = null;
            labelGridCount.Text = "/"+listDetail.Count.ToString();
            labelSelectNum.Text = listDetail.Count(s => s.IsPrint).ToString();
            gridControlshopProduct.DataSource = listDetail;
            ShopInGrid = listDetail;//双击格子赋值查询用
            //触发点击事件
            if (Properties.Settings.Default.PrintType == 0)
            { 
            }
            else if (Properties.Settings.Default.PrintType == 1)
            {
                button2_Click(null, null);
            }
            else if(Properties.Settings.Default.PrintType == 2)
            {
                buttonAllProduct_Click(null,null);
            }
        }

        public void RushOutShopGrid(MINERP.MODEL.DisjoinProForOutShop.OutShopGrid_Info grid)
        {
            ((OutShopUGrid)hashGrid[grid.GridId]).OutShopId = grid.OutShop.OutShopId;
            ((OutShopUGrid)hashGrid[grid.GridId]).OutShopName = grid.OutShop.OutShopName;
            ((OutShopUGrid)hashGrid[grid.GridId]).AllNum = grid.TotalCount;
            ((OutShopUGrid)hashGrid[grid.GridId]).CurrNum = grid.CurrentCount;
            //((OutShopUGrid)hashGrid[grid.GridId]).Grid = new Grid_Info() { GridId=grid.GridId,Status=grid.Status,SomeId=grid.SomeId,SubAreaId=grid.SubAreaId,GridName=grid.GridName };
            ((OutShopUGrid)hashGrid[grid.GridId]).Grid = grid;
            this._currentGrid = grid;
            //FrmMessage frm = new FrmMessage();
            //frm.labShow.Text = grid.GridName;
            //frm.Show();

        }

        public void RushShopGrid(MINERP.MODEL.DisjoinProForOutShop.ShopGrid_Info grid)
        {

            ((ShopUGrid)hashGrid[grid.GridId]).ShopId = grid.Shop.ShopId;
            ((ShopUGrid)hashGrid[grid.GridId]).ShopName = grid.Shop.ShopName;

            ((ShopUGrid)hashGrid[grid.GridId]).Grid = grid;
           if(grid.IsComplete)
           {
               ((ShopUGrid) hashGrid[grid.GridId]).BackColor = Color.LightBlue;
           }
            this._currentGrid = grid;
            //FrmMessage frm = new FrmMessage();
            //frm.labShow.Text = grid.GridName;
            //frm.Show();
        }

        #endregion

        private void tscDisType_DropDownClosed(object sender, EventArgs e)
        {
            int intSelect = tscDisType.SelectedIndex;
            if (intSelect != -1)
            {
                this.ShowType = tscDisType.SelectedIndex;
                if (intSelect == 0)
                {
                    splitContainer_Grid.Panel1Collapsed = false;
                    splitContainer_Grid.Panel2Collapsed = false;
                    if (_presenter != null)
                    {
                        hashGrid.Clear();
                        _presenter.InitialGrids();
                    }

                }
                else if (intSelect == 1)
                {
                    splitContainer_Grid.Panel1Collapsed = true;
                    splitContainer_Grid.Panel2Collapsed = false;
                    if (_presenter != null)
                    {
                        hashGrid.Clear();
                        _presenter.InitialGrids();
                    }

                }
                else
                {
                    splitContainer_Grid.Panel1Collapsed = false;
                    splitContainer_Grid.Panel2Collapsed = true;
                    if (_presenter != null)
                    {
                        hashGrid.Clear();
                        _presenter.InitialGrids();
                    }


                }
            }
        }

        private void splitContainer_Grid_Paint(object sender, PaintEventArgs e)
        {
            //if (_presenter != null)
            //{
            //    hashGrid.Clear();
            //    _presenter.InitialGrids();
            //}
            //if (_currentGrid != null)
            //{
            //    this.CurrentGrid = _currentGrid;
            //}
        }

        private void toolStripButtonClearGrid_Click(object sender, EventArgs e)
        {

            if (_currentGrid != null)
            {
                if (DialogResult.OK == MessageBox.Show("确认清空该格子", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    ((IGrid)hashGrid[_currentGrid.GridId]).ClearGrid();

                    _presenter.ClearCurrGrid();
                }
            }
            else
            {
                this.ShowMsg("请选择非空格子");
            }
        }
        public void ClearGrid()
        {
            if (hashGrid[_currentGrid.GridId] is ShopUGrid)
            {
                ShopUGrid aa = hashGrid[_currentGrid.GridId] as ShopUGrid;

                // aa.GridId = 0;
                // aa.GridName = "";
                aa.FristEnterTime = Convert.ToDateTime("2000-01-01"); ;
                aa.CompleteTime = Convert.ToDateTime("2000-01-01");
                //aa.Grid = null;
                aa.Grid.SomeId = 0;
                aa.ShopId = 0;

                aa.ShopName = "";
                aa.labelControlShopName.Text = "";
                aa.BackColor = Color.White;


            }
            else if (hashGrid[_currentGrid.GridId] is OutShopUGrid)
            {
                OutShopUGrid bb = hashGrid[_currentGrid.GridId] as OutShopUGrid;

                //  bb.GridId = 0;
                //   bb.GridName = "";
                //bb.Grid = null;
                bb.Grid.SomeId = 0;
                bb.FristEnterTime = Convert.ToDateTime("2000-01-01");
                bb.CompleteTime = Convert.ToDateTime("2000-01-01");


                bb.OutShopId = 0;
                bb.OutShopName = "";
                bb.AllNum = 0;
                bb.CurrNum = 0;
                bb.FristEnterTime = Convert.ToDateTime("2000-01-01");
                bb.labelControl_PhotoNumCurr.Text = "0";
                bb.labelControl_ProductNumAll.Text = "";
                bb.labelControlOutShopName.Text = "";
                bb.BackColor = Color.White;


            }
        }
        private void tsbtnPrint_Click(object sender, EventArgs e)
        {
            if (CurrentGrid==null)
            {
                this.ShowMsg("未选择格子");
                return;
            }
            toolStripLabelGridNam.Text =this.CurrentGrid.GridName;
            this.Text = "分堆--当前打印格子" + this.CurrentGrid.GridName;
            try
            {
                this.splitContainer_Grid.Enabled = false;
                tsbtnPrint.Enabled = false;
                toolStripTextBox_ProductBarCode.Text = "";
                toolStripTextBox_ProductBarCode.Enabled = false;
                toolStripButton_sure.Enabled = false;
                if (_currentGrid != null)
                {
                    //if (DialogResult.OK == MessageBox.Show("确认打印该格子", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    //{
                    //    this.Cursor = Cursors.WaitCursor;
                    //    _presenter.PrintGrid();
                    //}
                    //FrmMarkSure frmSure=new FrmMarkSure();

                    //if (DialogResult.OK == frmSure.ShowDialog())
                    //{
                    //    this.IsPrintFahuo = frmSure.checkBoxIsPrint.Checked;
                    //    this.Cursor = Cursors.WaitCursor;
                    _presenter.PrintGrid();
                    //}
                }
                else
                {
                    this.ShowMsg("请选择非空格子");
                }
            }
            catch (Exception ex)
            {

                this.ShowMsg(ex.Message);
            }
            finally
            {
                splitContainer_Grid.Enabled = true;
                tsbtnPrint.Enabled = true;
                toolStripTextBox_ProductBarCode.Enabled = true;
                toolStripButton_sure.Enabled = true;
                this.Cursor = Cursors.Default;
            }

        }

        private void timer_Check_Tick(object sender, EventArgs e)
        {
            _presenter.InitialGrids();
        }

        private void toolStripButton_sure_Click(object sender, EventArgs e)
        {
            string strProdCode = toolStripTextBox_ProductBarCode.Text.Trim();
            if (strProdCode.Trim() == "")
            {
                return;
            }
            if (strProdCode.Length != 10)
            {
                strProdCode = "2" + string.Format("{0:d9}", Convert.ToInt32(strProdCode));
            }
            _presenter.AssinGrid(strProdCode);
            this.toolStripTextBox_ProductBarCode.Text = "";
            strformBarcode = "";

            //if (toolStripTextBox_ProductBarCode.Text.Trim().Length != 10)
            //{
            //    MessageBox.Show("您输入的条码有误，请重新输入" , "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            //else
            //{
            //    _presenter.AssinGrid(toolStripTextBox_ProductBarCode.Text.Trim());
            //    this.toolStripTextBox_ProductBarCode.Text = "";
            //    strformBarcode = "";
            //}
        }

        private void toolStripButtonCancel_Click(object sender, EventArgs e)
        {
            this.Exit();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            MINERP.COM.Logoff.ShowMainFrm();
        }

        private void toolStripTextBox_ProductBarCode_Enter(object sender, EventArgs e)
        {
            this.KeyPreview = false;
        }

        private void toolStripTextBox_ProductBarCode_Leave(object sender, EventArgs e)
        {
            this.KeyPreview = true;
        }

        private void gridView_product_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            int rowNum = e.RowHandle;
            if (rowNum >= 0)
            {
                OverOrderView viewRow = (OverOrderView)gridView_product.GetRow(rowNum);
                if (viewRow.status.Equals("已分堆在格子中"))
                {
                    e.Appearance.BackColor = Color.LightSkyBlue;
                }
                //else
                //{
                //    viewRow.IsPrint = false;
                //}
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            FrmSelectInfo info = new FrmSelectInfo();
            info.Show();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            _presenter.RePrint();
        }
        public WorkShop_Info WorkShopParas { get { return base.workShopInfo; } }

        #region IFrmMain 成员


        public void ShowOutShopInfo(OutProcessShop_Info outShopInfo)
        {
            throw new NotImplementedException();
        }

        public void ShowShopInfo(Shop_Info shopInfo)
        {
            throw new NotImplementedException();
        }

        #endregion

        private void btnSearch_Click(object sender, EventArgs e)
        {
            //查询
            _presenter.SearchShopOrderInfo();
        }

        #region IFrmMain 成员

        public List<OverOrderView> ShopSelectItems
        {
            get
            {
                if (splitContainerControl_Botoom.PanelVisibility != SplitPanelVisibility.Both)
                {
                    //if (gridControlshopProduct.DataSource == null)
                    //{
                    return null;
                    //}
                }
                else //if equels both    
                {

                    if (gridControlshopProduct.DataSource != null)
                    {
                        List<OverOrderView> items = (List<OverOrderView>)gridControlshopProduct.DataSource;

                        return items.Where(i => i.IsPrint == true).ToList();
                    }
                    else
                    {
                        return null;
                    }
                }
            }
        }

        public List<OverOrderView> OutSelectItems
        {
            get
            {
                if (gridControl_product.DataSource == null)
                {
                    return null;
                }
                else
                {
                    return ((List<OverOrderView>)gridControl_product.DataSource).Where(ou => ou.IsPrint == true).ToList();
                }
            }
        }

        #endregion

        private void gridView_product_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            //if (e.Column.Name="IsEdit"&&e.Column.AppearanceCell.BackColor==)
            //{
            if (e.RowHandle >= 0)
            {
                OverOrderView viewRow = (OverOrderView)(gridView_product.GetRow(e.RowHandle));
                if(e.Column.Name=="GCIsPrint")
                {
                    if(viewRow.InGrid)
                    {
                        if(viewRow.IsPrint)
                        {
         
                            viewRow.IsPrint = false;
                        }
                        else
                        {
                            viewRow.IsPrint = true;

                        }
                    }
                    else
                    {
                        viewRow.IsPrint = false   ;
                    }
                }
            }
            //}
        }

        private void toolStripButtonSelectShop_Click(object sender, EventArgs e)
        {
            
            FrmSearch2 frm = new FrmSearch2();
            frm.SendGridColor += new FrmSearch2.SendSearch(frm_SendGridColor);
            frm.ShowDialog();
        }


        void frm_SendGridColor(int shopId, string shopName)
        {
            if (shopName != "")
            {

                foreach (DictionaryEntry item in hashGrid)
                {
                    if (item.Value is ShopUGrid)
                    {
                        ShopUGrid shopUGrid = item.Value as ShopUGrid;
                        if (shopUGrid.BackColor == Color.LightPink)
                        {
                            shopUGrid.BackColor = Color.White;
                        }
                        if (shopUGrid.ShopName.Contains(shopName) || shopUGrid.CtmName.Contains(shopName) || shopUGrid.OrderName.Contains(shopName))
                        {
                            shopUGrid.BackColor = Color.LightPink;
                        }
                    }
                }
            }
        }

        private void tsBtn_Seach_Click(object sender, EventArgs e)
        {

        }

        private void gridView_shopProduct_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            lblMsg.Text = "";
            try
            {
                if (e.RowHandle >= 0)
                {
                    OverOrderView view = ((OverOrderView) (gridView_shopProduct.GetRow(e.RowHandle)));
                    DateTime FetchTime = view.OrderFetchTime;
                    if ( DateTime.Now.CompareTo(FetchTime) > 0)
                    {
                        e.Appearance.BackColor = Color.Red;
                    }

                    if (!view.PreCountIsEnough)
                    {
                        lblMsg.Text = "有预估余额不足的产品！";
                        e.Appearance.BackColor = Color.Yellow;//预估余额不足
                    }
                    //if(view.OperateID==-1)
                    //{
                    //    gridView_shopProduct.set
                    //}
                }
            }
            catch (Exception)
            {


            }
        }

        private void toolStripButtonMessage_Click(object sender, EventArgs e)
        {
            frmMain frm = ComControls.frmMain.GetInstance(base.userId);
            frm.Show();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            FrmReCheck frm = new FrmReCheck();
            frm.Show();
        }

        private int selectType = 1;
        private void toolStripButtonMarkComplete_Click(object sender, EventArgs e)
        {
            FrmTpyeSelect frmTpyeSelect =new FrmTpyeSelect();
            frmTpyeSelect.SelectType += new FrmTpyeSelect.PostClicks(frmTpyeSelect_SelectType);
            if (frmTpyeSelect.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                foreach (DictionaryEntry item in hashGrid)
                {
                    if (item.Value is ShopUGrid)
                    {
                        ShopUGrid aa = item.Value as ShopUGrid;
                        if (!string.IsNullOrEmpty(aa.ShopName))
                        {

                            if (_presenter.IsComplete(aa.ShopId, selectType))
                            {
                                aa.BackColor = Color.Blue;
                            }
                        }
                    }
                }
            }
            this.Cursor = Cursors.Default;
        }

        void frmTpyeSelect_SelectType(int intType)
        {
            selectType = intType;
        }

        private void toolStripButtonSignAreaShop_Click(object sender, EventArgs e)
        {
            foreach (DictionaryEntry item in hashGrid)
            {
                if (item.Value is ShopUGrid)
                {
                    ShopUGrid aa = item.Value as ShopUGrid;
                    if (!string.IsNullOrEmpty(aa.ShopName))
                    {
                        if (aa.BackColor == Color.LightBlue || aa.BackColor == Color.Blue)
                        {
                            aa.BackColor = Color.White;
                        }
                        
                    }
                }
            }
            FrmSignShopByArea frm = new FrmSignShopByArea();
            frm.SendAreaGridColor += new FrmSignShopByArea.SendAreaSearch(frm_SendAreaGridColor);
            frm.ShowDialog();
        }

        void frm_SendAreaGridColor(List<Shop_Info> listShop)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                string strNoShop = "";
                string strPartShop = "";
                int intGridCount = hashGrid.Count;
                foreach (Shop_Info shop in listShop)
                {
                    bool isProduct = false;
                    int intFindCount = 0;
                    foreach (DictionaryEntry item in hashGrid)
                    {
                        if (item.Value is ShopUGrid)
                        {

                            ShopUGrid aa = item.Value as ShopUGrid;
                            //if (((UGrid)hashGrid[aa.GridId]).BackColor != Color.White)
                            //{
                            //    ((UGrid)hashGrid[aa.GridId]).BackColor = Color.White;
                            //}
                            // _presenter.IsComplete(aa.ShopId)

                            if (shop.ShopId == aa.ShopId)
                            {
                                int intComplete = _presenter.IsCompleteInt(shop.ShopId);

                                if (intComplete == 0)
                                {
                                    ((UGrid)hashGrid[aa.GridId]).BackColor = Color.Blue;
                                    isProduct = true;
                                    break;
                                }
                                else if (intComplete == 1)
                                {
                                    //strNoShop += aa.ShopName + ",";
                                    ((UGrid)hashGrid[aa.GridId]).BackColor = Color.LightBlue;
                                    isProduct = true;
                                    break;
                                }
                                else
                                {

                                }

                            }
                            else
                            {
                                // ((UGrid)hashGrid[aa.GridId]).BackColor = Color.White;
                            }

                        }
                        if (!isProduct)
                        {
                            intFindCount++;
                        }
                    }
                    if (intFindCount == intGridCount)
                    {
                        int intComplete = _presenter.IsCompleteInt(shop.ShopId);///在生产但是 全不没进格子
                        if (intComplete == 1)
                        {
                            strNoShop += shop.ShopName + ",";
                        }

                    }
                    //else
                    //{
                    //    int intComplete = _presenter.IsCompleteInt(shop.ShopId);///在生产但是 部分进格子
                    //    if (intComplete == 1)
                    //    {
                    //        strPartShop += shop.ShopName + ",";
                    //    }
                    //}

                }


                this.Cursor = Cursors.Default;
                if ("".Equals(strNoShop))
                {
                    //if (!isProduct)
                    //{
                    //    MessageBox.Show("该地区未有商户有订单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //    return;
                    //}
                    //else
                    //{
                    //    MessageBox.Show("该地区商户所有订单未到格子中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //    return;
                    //}
                }
                else
                {
                    MessageBox.Show("该地区以下商户有产品生产但是未在格子中" + Environment.NewLine + strNoShop.Trim(','), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch(Exception  exxx)
            {
                MessageBox.Show(exxx.Message);
 
            }

        }

       

        //private void gridView_shopProduct_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        //{
        //    if (e.RowHandle >= 0)
        //    {
        //        OverOrderView view = ((OverOrderView)(gridView_shopProduct.GetRow(e.RowHandle))); ;
        //        if (view.OperateID == -1)
        //        {
        //            e.DisplayText = "dsfhdshj";

        //        }
        //    }
        //}

        private void gridView_shopProduct_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
       
            if (e.RowHandle >= 0)
            {
                OverOrderView view = ((OverOrderView)(gridView_shopProduct.GetRow(e.RowHandle))); ;
                if (view.OperateID == -1)
                {
                    view.IsPrint = false;
                }
                else
                {
                    if (e.Column.Name == "gridColumn1")
                    {
                        // view.IsPrint = true;
                        if (view.IsPrint)
                        {
                            view.IsPrint = false;
                            view.PreCountIsEnough = true;
                        }
                        else
                        {
                            view.IsPrint = true;
                        }
                    }
                }
                var data=gridControlshopProduct.DataSource as List<OverOrderView>;
                labelSelectNum.Text = data.Count(s => s.IsPrint).ToString();
                   gridControlshopProduct.RefreshDataSource();
            }
        }

        private void gridView_shopProduct_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                OverOrderView viewRow = ((OverOrderView)(gridView_shopProduct.GetRow(e.RowHandle))); 
                if (e.Column.Name == "IsInGrid")
                {
                    if (viewRow.OperateID == -1)
                    {
                        e.DisplayText = "不在格子中";
                       
                    }
                    else
                    {
                        e.DisplayText = "在格子中";
                    }
                }
                //if(e.Column.Name=="gridColumn1")
                //{
                //    if (viewRow.OperateID == -1)
                //    {
                //        viewRow.IsPrint=false;
                //        ((RepositoryItemCheckEdit) e).DisplayValueChecked=true;
                //    }
                //    else
                //    {
                //        viewRow.IsPrint = true;
                //    }
                //}
            }
        }

        private void gridView_product_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                OverOrderView viewRow = ((OverOrderView)(gridView_product.GetRow(e.RowHandle)));
                if (e.Column.Name == "gridColumn2")
                {
                    if (!viewRow.InGrid )
                    {
                        e.DisplayText = "不在格子中";
                    }
                    else
                    {
                        e.DisplayText = "在格子中";
                    }
                }
                //if(e.Column.Name=="GCIsPrint")
                //{

                //    if (!viewRow.InGrid)
                //    {
                //        viewRow.IsPrint=false;
                //    }
                //    else
                //    {
                //        viewRow.IsPrint = true;
                //    }
                //}
            }
        }

        private void lblCurrentUser_Click(object sender, EventArgs e)
        {

        }

        private void buttonOutShopRecheck_Click(object sender, EventArgs e)
        {
            FrmOutShopReCheck frm = new FrmOutShopReCheck(CurrListForRecheck);
            frm.Show();

        }

        private void toolStripButtonKuaidi_Click(object sender, EventArgs e)
        {
            FrmShipping frmShipping =new FrmShipping();
            frmShipping.ShowDialog();
        }

        private void splitContainer_Grid_SplitterMoved(object sender, SplitterEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (!IsMouseClickGrid)
                {
                    _presenter.InitialGrids();
                }
            }
            catch (Exception ex)
            { }
            finally
            {
                this.Cursor = Cursors.Default;
            }

        }

        private void toolStripButtonImportOutProduct_Click(object sender, EventArgs e)
        {
            _presenter.ExportOutProduct();
        }

        private void buttonNOselect_Click(object sender, EventArgs e)
        {
            //List<GridDetailBase> viewList = (List<GridDetailBase>)gridControlshopProduct.DataSource;
            //viewList.ForEach(view=>view.IsPrint=false );
            //gridControlshopProduct.RefreshDataSource();
            List<OverOrderView> viewList = (List<OverOrderView>)gridControlshopProduct.DataSource;
            viewList.ForEach(view => view.IsPrint = false);
            gridControlshopProduct.RefreshDataSource();
            labelSelectNum.Text = viewList.Count(s => s.IsPrint).ToString();
        }

        private void toolStripButtonSelectTask_Click(object sender, EventArgs e)
        {
            FrmGetTaskList Frm = new FrmGetTaskList(this.TechId);
            Frm.Show();
        }
        bool needOpen = false;
        private void buttonAllProduct_Click(object sender, EventArgs e)
        {
            if (needOpen)
            {
                MessageBox.Show("请关闭格子重新打开");
                return;
            }
            needOpen = true;
            List<OverOrderView> viewList = (List<OverOrderView>)gridControlshopProduct.DataSource;
            //List<OverOrderView> viewList = (List<OverOrderView>)gridControlshopProduct.DataSource;
            //viewList.ForEach(each => each.IsPrint = false);
            //viewList.Where(view => view.isShuChu == false&&view.InGrid).ToList().ForEach(ec=>ec.IsPrint=true);
            //gridControlshopProduct.RefreshDataSource();
            foreach (OverOrderView orderView in viewList)
             {
                 //OverOrderView orderView = (OverOrderView)detailBase;
                 if (!orderView.InGrid)
                 {
                     continue;
                 }
                 orderView.IsPrint = false;
                 if (!orderView.isShuChu)
                 {
                     orderView.IsPrint = true;
                 }

             }
             gridControlshopProduct.RefreshDataSource();
            var data = gridControlshopProduct.DataSource as List<OverOrderView>;
             labelSelectNum.Text = data.Count(s => s.IsPrint).ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (needOpen)
            {
                MessageBox.Show("请关闭格子重新打开");
                return;
            }
            needOpen = true;
            List<OverOrderView> viewList = (List<OverOrderView>)gridControlshopProduct.DataSource;
            //viewList.ForEach(each => each.IsPrint = false);
            //viewList.Where(view => view.isShuChu).ToList().ForEach(ec => ec.IsPrint = true);
            //gridControlshopProduct.RefreshDataSource();

            foreach (OverOrderView orderView in viewList)
            {
                //OverOrderView orderView = (OverOrderView)detailBase;
                if (!orderView.InGrid)
                {
                    continue;
                }
                orderView.IsPrint = false;
                if (orderView.isShuChu)
                {
                    orderView.IsPrint = true;
                }

            }
            gridControlshopProduct.RefreshDataSource();
            var data = gridControlshopProduct.DataSource as List<OverOrderView>;
            labelSelectNum.Text = data.Count(s => s.IsPrint).ToString();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {

        }

        private void toolStripComboBoxPrintType_DropDownClosed(object sender, EventArgs e)
        {
            Properties.Settings.Default.PrintType = toolStripComboBoxPrintType.SelectedIndex;
            Properties.Settings.Default.Save();
        }

        private void gridView_shopProduct_MouseMove(object sender, MouseEventArgs e)
        {
            if ( e.Button == MouseButtons.Left)
            {
                
            }
        }

        private void gridView_shopProduct_MouseMove_1(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                GridView view = sender as GridView;
                GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));
                //this.Text = hitInfo.RowHandle.ToString();
                //DataRow row = view.GetDataRow(hitInfo.RowHandle);
                //var data = view.GetDataRow(hitInfo.RowHandle);
                if (hitInfo.RowHandle >= 0)
                {
                    OverOrderView data = gridView_shopProduct.GetRow(hitInfo.RowHandle) as OverOrderView;
                    data.IsPrint = true;
                    view.RefreshRow(hitInfo.RowHandle);
                }
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            FrmNewProject frm = new FrmNewProject();
            frm.Show();
        }

     

        

        

        //private void gridView_shopProduct_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        //{
        //    if(e.RowHandle>=0)
        //    {
        //          OverOrderView viewRow = (OverOrderView)gridView_product.GetRow(e.RowHandle);
        //        if(viewRow.OperateID==-1)
        //        {
        //            e.
        //        }
        //    }
        //}




    }
}
